//
//  workbenchView.m
//  DJS
//
//  Created by mac on 2017/12/26.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "workbenchView.h"
#import "LawListViewController.h"
#import "DocumentListViewController.h"
#import "ContractListViewController.h"
#import "TiXianViewController.h"
#import "BalancePaymentsViewController.h"
#import "CaseListViewController.h"
#import "CaseListViewController.h"
#import "BalancePayments2ViewController.h"
#import "NewsViewController.h"
#import "WEBViewController.h"
@implementation workbenchView

-(void)creatView{
    
     self.backgroundColor=_LightGrey;
    _scrollView=[UIScrollView new];
    [self addSubview:_scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    _scrollView.scrollsToTop =NO;
    
    _scrollView.showsVerticalScrollIndicator = FALSE;
    _scrollView.showsHorizontalScrollIndicator = FALSE;
    _scrollView.bounces = NO;
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.viewController.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    
    UIView *topView=[UIView new];
    [_scrollView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(NAV_HEIGHT+10);
        make.width.mas_equalTo(_mainW-30);
        make.height.mas_equalTo(260);
    }];
    [self creatTopView:topView];
    
    UIView *renWuView=[UIView new];
    [_scrollView addSubview:renWuView];
    [renWuView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(topView.mas_bottom).mas_equalTo(15);
        make.width.mas_equalTo(_mainW);
        make.height.mas_equalTo(60);
    }];
    renWuView.backgroundColor=[UIColor whiteColor];
    [self creatRenWuView:renWuView];
    
    UIView *gongZuoView=[UIView new];
    [_scrollView addSubview:gongZuoView];
    [gongZuoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(renWuView);
        make.height.mas_equalTo(232);
        make.top.mas_equalTo(renWuView.mas_bottom).mas_equalTo(15);
    }];
    gongZuoView.backgroundColor=[UIColor whiteColor];
    [self creatGongZuoView:gongZuoView];
    
    UIView *QiTaView=[UIView new];
    [_scrollView addSubview:QiTaView];
    [QiTaView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(renWuView);
        make.height.mas_equalTo(151);
        make.top.mas_equalTo(gongZuoView.mas_bottom).mas_equalTo(15);
    }];
    QiTaView.backgroundColor=[UIColor whiteColor];
    [self creatQiTaView:QiTaView];
    
    _scrollView.contentSize = CGSizeMake(0,940);
}

-(void)creatTopView:(UIView *)topView{
    UIImageView *imageView=[UIImageView new];
    [topView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.bottom.mas_equalTo(0);
    }];
    imageView.layer.cornerRadius=10;
    imageView.image=[UIImage imageNamed:@"卡"];
    
    UILabel *timeLable=[UILabel new];
    [topView addSubview:timeLable];
    [timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(15);
    }];
    timeLable.textColor=[UIColor whiteColor];
    timeLable.font=[UIFont systemFontOfSize:20];
    NSString *xinQi=[self weekdayStringFromDate:[NSDate new]];
    NSString *mmDD=[ZQTools changeTimeCuo:@"MM-dd" :[ZQTools NSDateToTimeCuo:[NSDate new]]];
    timeLable.text=[NSString stringWithFormat:@"%@  %@",mmDD,xinQi];
    
    UIButton *btn=[UIButton new];
    [topView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(70);
        make.centerY.mas_equalTo(timeLable);
    }];
    btn.layer.cornerRadius=5;
    btn.layer.borderColor=[UIColor whiteColor].CGColor;
    btn.layer.borderWidth=1;
    btn.backgroundColor=[UIColor clearColor];
    [btn setTitle:@"提现" forState:0];
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    [btn addTarget:self action:@selector(tiXian:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *label=[UILabel new];
    [topView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(80);
    }];
    label.text=@"余额（元）";
    label.font=[UIFont systemFontOfSize:18];
    label.textColor=[UIColor whiteColor];
    
    NSNumber *waiter_balance=[_userDic objectForKey:@"waiter_balance"];
    if (waiter_balance==nil) {
        waiter_balance=@0;
    }
    CGSize size=[ZQTools getNSStringWeight:[NSString stringWithFormat:@"%@",waiter_balance] andViewWight:30 andFont:24];
    UILabel *label2=[UILabel new];
    [topView addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(label.mas_bottom).mas_equalTo(20);
        make.width.mas_equalTo(size.width+20);
    }];
    label2.text=[NSString stringWithFormat:@"%@",waiter_balance];
    label2.textColor=[UIColor whiteColor];
    label2.font=[UIFont systemFontOfSize:24];
    
    UILabel *ChaKanLabel=[UILabel new];
    [topView addSubview:ChaKanLabel];
    [ChaKanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label2.mas_right).mas_equalTo(15);
        make.bottom.mas_equalTo(label2);
    }];
    ChaKanLabel.text=@"查看明细";
    ChaKanLabel.font=[UIFont systemFontOfSize:14];
    ChaKanLabel.textColor=[UIColor whiteColor];
    ChaKanLabel.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chanKan:)];
    [ChaKanLabel addGestureRecognizer:tapGesture];
    
    UIView *xianView=[UIView new];
    [topView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(label2.mas_bottom).mas_equalTo(20);
        make.height.mas_equalTo(1);
    }];
    xianView.backgroundColor=[UIColor whiteColor];
    
    UIView *xianView2=[UIView new];
    [topView addSubview:xianView2];
    [xianView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.width.mas_equalTo(1);
        make.top.mas_equalTo(xianView.mas_bottom).mas_equalTo(7);
        make.bottom.mas_equalTo(-7);
    }];
    xianView2.backgroundColor=[UIColor whiteColor];
    
    NSNumber *waiter_income=[_userDic objectForKey:@"waiter_income"];
    if (waiter_income==nil) {
        waiter_income=@0;
    }
    UIView *view=[UIView new];
    [topView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.mas_equalTo(0);
        make.top.mas_equalTo(xianView.mas_bottom);
        make.right.mas_equalTo(xianView2.mas_left);
    }];
    UITapGestureRecognizer *tapGesture12 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chanKan:)];
    [view addGestureRecognizer:tapGesture12];
    
    
    
    UILabel *label3=[UILabel new];
    [view addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(15);
    }];
    label3.text=[NSString stringWithFormat:@"%@",waiter_income];
    label3.font=[UIFont systemFontOfSize:18];
    label3.textColor=[UIColor whiteColor];
    
    UILabel *label4=[UILabel new];
    [view addSubview:label4];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(-15);
    }];
    label4.text=@"我的收益（元）";
    label4.font=[UIFont systemFontOfSize:18];
    label4.textColor=[UIColor whiteColor];
    
    NSNumber *waiter_line_income=[_userDic objectForKey:@"waiter_line_income"];
    if (waiter_line_income==nil) {
        waiter_line_income=@0;
    }
    
    UIView *view2=[UIView new];
    [topView addSubview:view2];
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(xianView.mas_bottom);
        make.left.mas_equalTo(xianView2.mas_right);
    }];
    
    UITapGestureRecognizer *tapGesture13 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(chanKan2:)];
    [view2 addGestureRecognizer:tapGesture13];
    UILabel *label5=[UILabel new];
    [view2 addSubview:label5];
    [label5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(15);
    }];
    label5.text=[NSString stringWithFormat:@"%@",waiter_line_income];
    label5.font=[UIFont systemFontOfSize:18];
    label5.textColor=[UIColor whiteColor];
    
    UILabel *label6=[UILabel new];
    [view2 addSubview:label6];
    [label6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(-15);
    }];
    label6.text=@"线下收益（元）";
    label6.font=[UIFont systemFontOfSize:18];
    label6.textColor=[UIColor whiteColor];
    
    
}
-(void)creatRenWuView:(UIView *)topView{
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pusToRenWu:)];
    [topView addGestureRecognizer:tapGesture];
    
    UIImageView *iamgeView=[UIImageView new];
    [topView addSubview:iamgeView];
    [iamgeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(18);
    }];
    iamgeView.image=[UIImage imageNamed:@"任务"];
    UILabel *label=[UILabel new];
    [topView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(iamgeView.mas_right).mas_equalTo(15);
        make.centerY.mas_equalTo(0);
    }];
    label.text=@"任务";
    label.font=[UIFont systemFontOfSize:18];
    label.textColor=ColorWithRGB(29, 29, 29);
    
    UIView *dianView=[UIView new];
    [topView addSubview:dianView];
    [dianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(100);
        make.width.height.mas_equalTo(4);
    }];
    dianView.layer.cornerRadius=2;
    dianView.backgroundColor=[UIColor redColor];
    
    UIImageView *iamgeView2=[UIImageView new];
    [topView addSubview:iamgeView2];
    [iamgeView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(36);
        make.height.mas_equalTo(24);
    }];
    iamgeView2.image=[UIImage imageNamed:@"更多"];
    
}
-(void)pusToRenWu:(UITapGestureRecognizer *)tap{
    
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }

 
    
    NewsViewController *viewContro=[[NewsViewController alloc] init];
    viewContro.message_type=@"1";
    [ZQTools pushNextViewController:self.viewController andRootController:viewContro];
}

-(void)creatGongZuoView:(UIView *)topView{
    
    UIView *view=[UIView new];
    [topView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    UIView *xianView4=[UIView new];
    [topView addSubview:xianView4];
    [xianView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(view.mas_bottom);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    xianView4.backgroundColor=_LightGrey;
    
    UIView *view2=[UIView new];
    [topView addSubview:view2];
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(181);
    }];
    
    UIView *xianView=[UIView new];
    [view addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(3);
    }];
    xianView.backgroundColor=_backgroundColor;
    
    UILabel *label=[UILabel new];
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(xianView.mas_right).mas_equalTo(15);
        make.centerY.mas_equalTo(0);
    }];
    label.text=@"工作";
    label.textColor=ColorWithRGB(29, 29, 29);
    label.font=[UIFont systemFontOfSize:18];
    
    NSArray *nameArr=[NSArray arrayWithObjects:@"法律咨询",@"代写文书",@"案件委托", nil];
    int index=0;
    for (int i=0; i<2; i++) {
        for (int j=0;j<2 ; j++) {
            
            if (index==3) {
                continue;
            }
            UIView *beiJingView=[UIView new];
            [view2 addSubview:beiJingView];
            [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(j*(_mainW)/2);
                make.width.mas_equalTo((_mainW)/2);
                make.top.mas_equalTo(i*91);
                make.height.mas_equalTo(90);
            }];
            
            beiJingView.userInteractionEnabled=YES;
            beiJingView.tag=index;
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectZhuangTai:)];
            [beiJingView addGestureRecognizer:tapGesture];
            
            UIImageView *image=[UIImageView new];
            [beiJingView addSubview:image];
            [image mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.mas_equalTo(0);
                make.centerX.mas_equalTo(-50);
                make.width.height.mas_equalTo(40);
            }];
            image.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@1",nameArr[index]]];
            
            UILabel *label=[UILabel new];
            [beiJingView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.mas_equalTo(image);
                make.left.mas_equalTo(image.mas_right).mas_equalTo(20);
            }];
            label.text=nameArr[index];
            label.textColor=ColorWithRGB(49, 49, 49);
            label.font=[UIFont systemFontOfSize:16];
           
            index+=1;
        }
    }
    UIView *xianView3=[UIView new];
    [view2 addSubview:xianView3];
    [xianView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
        make.centerY.mas_equalTo(0);
    }];
    xianView3.backgroundColor=_LightGrey;
    
    UIView *xianView2=[UIView new];
    [view2 addSubview:xianView2];
    [xianView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.centerX.mas_equalTo(0);
        make.width.mas_equalTo(1);
    }];
    xianView2.backgroundColor=_LightGrey;
    
    
}
-(void)creatQiTaView:(UIView *)topView{
    UIView *view=[UIView new];
    [topView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    UIView *xianView4=[UIView new];
    [topView addSubview:xianView4];
    [xianView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(view.mas_bottom);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    xianView4.backgroundColor=_LightGrey;
    
    UIView *view2=[UIView new];
    [topView addSubview:view2];
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(100);
    }];
    
    UIView *xianView=[UIView new];
    [view addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(3);
    }];
    xianView.backgroundColor=_backgroundColor;
    
    UILabel *label=[UILabel new];
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(xianView.mas_right).mas_equalTo(15);
        make.centerY.mas_equalTo(0);
    }];
    label.text=@"其他";
    label.textColor=ColorWithRGB(29, 29, 29);
    label.font=[UIFont systemFontOfSize:18];
    
    
    NSArray *nameArr=[NSArray arrayWithObjects:@"律师费计算",@"诉讼费计算", nil];

    for (int i=0; i<2; i++) {
        
      
            UIView *beiJingView=[UIView new];
            [view2 addSubview:beiJingView];
            [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(i*(_mainW)/3);
                make.width.mas_equalTo((_mainW)/3);
                make.top.mas_equalTo(0);
                make.height.mas_equalTo(100);
            }];
            
            beiJingView.userInteractionEnabled=YES;
            beiJingView.tag=i;
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToXiaZai:)];
            [beiJingView addGestureRecognizer:tapGesture];
        
            UIImageView *image=[UIImageView new];
            [beiJingView addSubview:image];
            [image mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(15);
                make.centerX.mas_equalTo(0);
                make.height.mas_equalTo(40);
                make.width.mas_equalTo(25);
            }];
     
            image.image=[UIImage imageNamed:nameArr[i]];
        
            UILabel *label=[UILabel new];
            [beiJingView addSubview:label];
            [label mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.mas_equalTo(0);
                make.top.mas_equalTo(image.mas_bottom).mas_equalTo(15);
            }];
            label.textColor=ColorWithRGB(49, 49, 49);
            label.font=[UIFont systemFontOfSize:16];
            label.text=nameArr[i];

        }
    for (int i=0; i<3; i++) {
        UIView *xianView2=[UIView new];
        [view2 addSubview:xianView2];
        [xianView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(i*_mainW/3);
            make.top.bottom.mas_equalTo(0);
            make.width.mas_equalTo(1);
        }];
        xianView2.backgroundColor=_LightGrey;
    }
  
}

-(IBAction)tiXian:(id)sender{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }

    tiXianViewController *tiXian=[[tiXianViewController alloc] init];
    [ZQTools pushNextViewController:self.viewController andRootController:tiXian];
    
}
-(void)chanKan:(UITapGestureRecognizer *)tap{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }

    BalancePaymentsViewController *af=[[BalancePaymentsViewController alloc] init];
    [ZQTools pushNextViewController:self.viewController andRootController:af];
}
-(void)chanKan2:(UITapGestureRecognizer *)tap{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }

    BalancePayments2ViewController *af=[[BalancePayments2ViewController alloc] init];
    [ZQTools pushNextViewController:self.viewController andRootController:af];
}
-(void)selectZhuangTai:(UITapGestureRecognizer *)tap{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }

    if (tap.view.tag==0) {
        LawListViewController *lawList=[[LawListViewController alloc] init];
        [ZQTools pushNextViewController:self.viewController andRootController:lawList];
    }
    if (tap.view.tag==1) {
        DocumentListViewController *lawList=[[DocumentListViewController alloc] init];
        lawList.business_type=@"1";
        [ZQTools pushNextViewController:self.viewController andRootController:lawList];
    }
  if (tap.view.tag==2) {
        CaseListViewController *lawList=[[CaseListViewController alloc] init];
        [ZQTools pushNextViewController:self.viewController andRootController:lawList];
    }

    
}
-(void)pushToXiaZai:(UITapGestureRecognizer *)tap{
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    if (userDic==nil) {
        [ZQTools ToLoging:self.viewController];
        return;
    }

    if (tap.view.tag==0) {
        WEBViewController *web=[[WEBViewController alloc]init];
        web.url=@"http://www.djiaoshou.com/index/index/lawyer_calculator.html?source=1";
        [ZQTools pushNextViewController:self.viewController andRootController:web];
    }
    if (tap.view.tag==1) {
        WEBViewController *web=[[WEBViewController alloc]init];
        web.url=@"http://www.cnado.com/";
        [ZQTools pushNextViewController:self.viewController andRootController:web];
    }
    
  
}

- (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"Sunday", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit calendarUnit = NSWeekdayCalendarUnit;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
    
}


@end
